﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CCF20Model;
using System.Windows;
using System.Collections;
using WiseLink.RDS.Resource;

namespace CCF20Module.DeviceState
{
    public class InStockState : DeviceStateBase
    {

        public InStockState(IDeviceHandler handler, DeviceModel model,VehicleModel vModel, Device device, IList list)
            : base(handler, model,vModel, device, list)
        {
            this.failReason = DeviceStatus.InStock; 
            StateName = DeviceStatus.InStock;
            //LoggerHelper.LogCCF20("进入库存状态初始化");
        }

        #region ExecuteAction

        public override string runInStock()
        {
            // do nothing
            this.failReason = string.Format("IDC={0} {1}", currentDevice.IDCSimNumber, DeviceStatus.InStock);
            return base.runInStock();
            
        }

        public override string runSellToCustomer(int customerId)
        {

            if (!IsSavedDevice(out failReason))
            {
                return failReason;
            }

            string result;
            CCF20Model.Customer customer = deviceModel.CanSellCustomer(customerId,currentDevice.IDCSimNumber, out result);
            if (customer != null)
            {
                if (customer.IsPreOrder == true)
                {
                    //ccfZic.RemovePreOrder(customer.CustomerNo);
                }
                currentDevice.Customer = customer;
                currentDevice.Vehicle = customer.Vehicles.FirstOrDefault();
                currentDevice.DeviceStatus = DeviceStatus.Sold;
                currentDevice.SaleDate = DateTime.Now;
                currentDevice.Sales = (string)Application.Current.Properties["CurrentUser"];
                customer.IsPreOrder = false;
                InitializeVehicleState();
                deviceModel.Update();
                this.deviceHandler.setState(deviceHandler.getSellToCustomerState());
                return string.Format(Message.Device_Sold_Succeed, currentDevice.IDCSimNumber, customer.Name);
            }
            else
            {
                this.failReason = result;
                return base.runSellToCustomer(customerId);
            }
            
        }

        public override string runRegisterIDC()
        {
            return base.runRegisterIDC();
        }
        public override string runUnRegisterIDC()
        {
            return base.runUnRegisterIDC();
        }
        public override string runRegisterSpeicalIDC()
        {
            return base.runRegisterSpeicalIDC();
        }
        public override string runUnRegisterSpeicalIDC()
        {
            return base.runUnRegisterSpeicalIDC();
        }

        

        public override string runReturnDevice()
        {
            return base.runReturnDevice();
        }

        
        public override string runDeleteDevice()
        {
            return base.DeleteDevice();
        }

        #endregion
    }
}
